package org.JWCB.friend.rabbitmq;


import lombok.extern.slf4j.Slf4j;
import org.JWCB.api.domain.judge.dto.JudgeSubmitDto;
import org.JWCB.common.core.constants.RabbitMQConstants;
import org.JWCB.common.core.enums.ResultCode;
import org.JWCB.common.core.exception.ServiceException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class JudgeProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void produceJudgeMsg(JudgeSubmitDto judgeSubmitDto){
        try {
            log.info("生产者发送消息");
            rabbitTemplate.convertAndSend(RabbitMQConstants.OJ_WORK_QUEUE,judgeSubmitDto);
        }catch (Exception e) {
            log.error("生产者发送消息异常",e);
            throw new ServiceException(ResultCode.FAILED);
        }
    }
}
